﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Odbc;
using System.Data;
using Dapper;
using System.Dynamic;
using System.Text.RegularExpressions;
using _180FrameWork.DataBaseHelper.Entities;

namespace _180FrameWork.DataBaseHelper
{
    public class DapperHelper : IDisposable
    {
      
        protected Database _db;

        protected DbConnection _Conn;

        public DbConnection Conn
        {
            get
            {
                if (_Conn == null)
                    _Conn = this._db.CreateConnection();
                return this._Conn;
            }
        }

        public DapperHelper()
        {
            //_db = DatabaseFactory.CreateDatabase();
        }

        public DapperHelper(string DBName)
        {
            if (DBName.Trim() == "")
                _db = DatabaseFactory.CreateDatabase();
            else
                _db = DatabaseFactory.CreateDatabase(DBName.Trim());
        }

        public void Dispose()
        {
            if (_Conn != null && _Conn.State == ConnectionState.Open)
            {
                _Conn.Close();
            }
            if (_Conn != null)
            {
                _Conn.Dispose();
            }
        }

        
        
    }
}
